// 一个纯粹的会话对象，负责「装数据」，不要放业务逻辑
class Session {
  final String? token;
  final String? unionid;
  final String? merchantId;
  final String? role;
  final List<String>? scopes;

  const Session({this.token, this.unionid, this.merchantId, this.role, this.scopes});

  // 用于 SharedPreferences ↔︎ Session 的互转
  Map<String, dynamic> toMap() => {
    'token': token,
    'unionid': unionid,
    'merchantId': merchantId,
    'role': role,
    'scopes': scopes,
  };

  factory Session.fromMap(Map<String, dynamic>? map) => Session(
    token: map?['token'],
    unionid: map?['unionid'],
    merchantId: map?['merchantId'],
    role: map?['role'],
    scopes: (map?['scopes'] as List?)?.cast<String>(),
  );
}
